<?php
/**
 * Zhub - A PHP Framework For API Developer
 *
 * This file is part of the Zhub package.
 *
 * (c) YiLong Fan <fantiq@163.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author fanyilong <fantiq@163.com>
 * @copyright 2017 fanyilong. All rights reserved.
 * @package Zhub
 * @date 18-3-6
 */

namespace Zhub\DataBase\Tables;


class Field
{
    // int
    // 2^(8 * 1)
    const NUM_TINYINT = 0;
    // 2^(8 * 2)
    const NUM_SMALLINT = 0;
    // 2^(8 * 3)
    const NUM_MEDIUMINT = 0;
    // 2^(8 * 4)
    const NUM_INT = 0;
    // 2^(8 * 8)
    const NUM_BIGINT = 0;

    const FLOAT = 0;
    const DOUBLE = 0;
    const DECIMAL = 0;

    const STR_CHAR = 0;
    const STR_VARCHAR = 1;

    private $isStr = false;

    private $name = null;

    private $alias = null;

    public static function name(string $name, string $alias = null)
    {
        return new self($name, $alias);
    }

    public function __construct(string $name, string $alias = null)
    {
        $this->name = $name;
        $this->alias = $alias ? $alias : $this->name;
    }

    public function integer(int $type, bool $unsigned = true, int $default = 0)
    {
        $this->isStr = false;
        return $this;
    }

    public function decimal(int $type, bool $unsigned = true)
    {
        return $this;
    }

    public function string(int $type, int $len = 0, string $default = '')
    {
        $this->isStr = true;
        return $this;
    }

    public function comment(string $comment = '')
    {
        return $this;
    }

    public function isString():string
    {
        return $this->isStr;
    }

    public function __toString():string
    {
        return $this->getFieldName();
    }

    public function getFieldName():string
    {
        return $this->name;
    }

    public function getFieldAliasName():string
    {
        return $this->alias;
    }
}
